function createScatterSeries(datasource:any, name: string, colorCondition: string, color: string, datatype: string, isLarge: boolean) {
    const adjustmentsX :any = {
        'gene': 0.5,
        'methy': 0.5,
        'exp': 0,
        'protein': 0,
        'drug': 0.01,
    };
    const adjustmentsY :any = {
        'gene': 1, 
        'methy': 1, 
        'exp': 1,
        'protein': 0.5,
        'drug': 0.5,
    };
    const markLineOption: any = {
        'exp': [
            { xAxis: 2, label: { show: false } },
            { yAxis: 3, label: { show: false } },
        ],
        'drug': [
            { xAxis: 2, label: { show: false } },
            { yAxis: 2.5, label: { show: false } },
        ],
        'protein': [
            { xAxis: 2, label: { show: false } },
            { yAxis: 2.5, label: { show: false } },
        ],
        'gene': [
            { xAxis: 2.5, label: { show: false } },
            { yAxis: 3, label: { show: false } },
        ],
        'methy': [
            { xAxis: 2.5, label: { show: false } },
            { yAxis: 3, label: { show: false } },
        ],
    }

    const getMappedItem = (item:any, datatype:any) => {
        const drugName = datatype === 'drug' ? item['Drug.Name'] : item['drug_name']; // 选择Drug.Name或drug_name
        return [
            item['P.Value_Single_log'] + adjustmentsX[datatype], //0
            item['P.Value_Pancancer_log'] + adjustmentsY[datatype], //1
            item['Color'], //2
            item['label'], //3
            item['TumorType'], //4
            item['P.Value_Single'], //5
            item['P.Value_Pancancer'], //6
            item['logFC_Single'], //7
            item['logFC_Pancancer'], //8
            item['Target_Genes'], //9
            item['repurposing_target'], //10
            item['MOA'], //11
            item['IDs'], //12
            drugName, //13
            item['data_type'], //14
            item['showLabel'] //15
        ];
    };

    const data = datasource.map((item:any) => getMappedItem(item, datatype))

    return {
        name: name,
        type: 'scatter',
        large: isLarge,
        symbolSize: 7,
        data: data,
        label: {
            show: !isLarge,  // isLarge为true 不显示label，isLarge为false 显示label
            position: 'top',  
            formatter: function (params:any) {
                return params.value[3];
            },
            color: color,
            fontSize: 12,
        },
        labelLayout: {
            hideOverlap: true
        },
        markLine: {
            lineStyle: {
                type: 'dashed',
                color: 'yellow',
                width: 2
            },
            data: markLineOption[datatype],
            symbol: ['none', 'none']
        },
        itemStyle: {
            color: color
        }
    };
}

/*
    row:any, column:any 占位使用
*/
function formatDecimal(row:any, column:any, cellValue:any) {
    let res = null
    if (typeof cellValue === 'number') {
        // 判断是否是科学计数法的形式
        if (cellValue.toString().includes('e')) {
            // 使用 toExponential(6) 保留小数点后 6 位的科学计数法表示
            res = cellValue.toExponential(6);
        } else {
            // 否则保留6位小数
            res = cellValue.toFixed(6);
        }
    } else if (typeof cellValue === 'string') {
        let num = Number(cellValue);
        if (!isNaN(num)) {
            if (cellValue.includes('E')) {
                // 将字符串转换为科学计数法格式并保留 6 位小数
                res = num.toExponential(6);
            } else {
                // 保留6位小数
                res = num.toFixed(6);
            }
        } else {
            // 不是数字类型，截取字符串前7位
            res = cellValue.slice(0, 7);
        }
    }
    return res; // 保留两位小数
}

export {
    createScatterSeries,
    formatDecimal
}